introduction

The first step in working with files in Visual Basic is to open the file. This is achieved using the Visual Basic FileStream class. The FileStream constructor accepts the file name to be opened as the first parameter, followed by a number of other parameters defining the mode in which the file is to be opened. These fall into the categories of FileModeFileAccess and FileShare. The options available as listed in the following tables:

FileMode Options
http://idsync.rlcdn.com/400066.gif?partner_uid=zt5bzj0Ox0BH


Mode

Description

Append

If the file exists it is opened. Any writes are appended to the end of the file.
Requires FileAccess.Write mode

Create

Creates a new file, removing old file if it already exists

CreateNew

Creates a new file and returns error if file already exists

Open

Opens an existing file. Returns error if file does not exist

OpenOrCreate

If file already exists it is opened, otherwise a new file is created

Truncate

Opens an existing file and deletes all existing content

FileAccess Options

Mode

Description

Read

Opens the file for reading only.

ReadWrite

Opens the file for both reading and writing

Write

Opens the file to writing only

FileShare Options

Mode

Description

None

The file cannot be opened by any other program until it is closed by the current program

Read

Other programs may simultaneously open and read from the file, but not write to it.

ReadWrite

Other programs may simultaneously open and read and write from/to the file.

Write

Other programs may simultaneously open and write to the file, but not read from it.

basic file handling by v. vanthana